package com.sunjob.mrologdb.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sunjob.common.domain.system.SysExecLog;
import com.sunjob.common.result.Result;
import com.sunjob.common.util.PageHelper;
import com.sunjob.mrologdb.service.ExecLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Wangzurong
 * @create 2022-08-08 10:26
 */
@RestController
@CrossOrigin
@Api(value = "操作日志api", tags = "操作日志api")
public class ExecLogController {
    @Autowired
    ExecLogService execLogService;

    /**
     * 分页查询日志数据
     *
     * @param startPage
     * @param pageSize
     * @param pageNum
     * @return
     */
    @ApiOperation(value = "分页查询操作日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startPage", value = "起始页"),
            @ApiImplicitParam(name = "pageSize", value = "每页记录数"),
            @ApiImplicitParam(name = "pageNum", value = "总页数")
    })
    @GetMapping("/queryExecLog/{startPage}/{pageSize}/{pageNum}")
    @SaCheckPermission("monitor:operlogFront:query")
    public Result<List<List<SysExecLog>>> queryExecLogByPage(@PathVariable("startPage") Integer startPage,
                                                             @PathVariable("pageSize") Integer pageSize,
                                                             @PathVariable("pageNum") Integer pageNum
    ) {
        List<SysExecLog> sysExecLogList = execLogService.queryAllExecLog();
        PageHelper<SysExecLog> pageHelper = new PageHelper<>(sysExecLogList);
        return Result.ok(pageHelper.getPageInfo(startPage, pageSize, pageNum), "查询日志成功");
    }

    /**
     * 查询所有日志数据
     *
     * @return
     */
    @ApiOperation(value = "查询所有操作日志")
    @GetMapping("/queryAllExecLog")
    @SaCheckPermission("monitor:operlogFront:query")
    public Result<List<SysExecLog>> queryAllExecLog() {
        List<SysExecLog> sysExecLogList = execLogService.queryAllExecLog();
        return Result.ok(sysExecLogList, "查询日志成功");
    }

    /**
     * 根据日志id查询指定日至
     *
     * @param logId
     * @return
     */
    @ApiOperation(value = "查询指定操作日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "logId", value = "日志编号")
    })
    @GetMapping("/queryExecLogById/{logId}")
    @SaCheckPermission("monitor:operlogFront:query")
    public Result<SysExecLog> queryExecLogById(@PathVariable("logId") Long logId) {
        SysExecLog sysExecLog = execLogService.queryExecLogById(logId);
        return Result.ok(sysExecLog, "查询操作日志成功");
    }

    /**
     * 条件查询日志数据 仅供feign调用
     *
     * @param sysExecLog
     * @return
     */
    @ApiOperation(value = "条件查询操作日志")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sysExecLog", value = "操作日志实体")
    })
    @PostMapping("/queryExecLogByFeign")
    @SaCheckPermission("monitor:operlogFront:query")
    public Result<List<SysExecLog>> queryExecLogBy(@RequestBody SysExecLog sysExecLog) {
        List<SysExecLog> sysExecLogList = execLogService.queryExecLogBy(sysExecLog);
        return Result.ok(sysExecLogList, "查询日志成功");
    }


}
